package com.example.demo53.ui.Temperation;


import android.graphics.Color;
import android.os.Bundle;

import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.color3.colorpicker.ColorPicker;
import com.example.demo53.R;

import com.gcssloop.widget.ArcMaskCircilarView;
import com.gcssloop.widget.ArcSeekBar;

import java.security.PublicKey;


public class double_color_temp extends AppCompatActivity {
    private TextView mProgressText;
    private SeekBar dseek1;
    private TextView tv_dseek1;
    private ImageView light_icon;
    private ArcSeekBar mArcSeekBar;
    private int gray = -8355712;
    private int color_icon= gray;
    private ArcMaskCircilarView arcMaskCircilarView ;
    private int mcolor;
    private float mHue;//色调范围0-360
    private float mSat;//饱和度范围0-1
    private float mVal;//亮度范围0-1
    float[] hsv = new float[3];

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.double_colortemp_controller);
        mProgressText = findViewById(R.id.txt_progress);
        mArcSeekBar = findViewById(R.id.arc_seek_bar);
        mArcSeekBar.setArcColors(R.array.arc_colors_custom);

        light_icon=findViewById(R.id.icon_dlight);
        dseek1=findViewById(R.id.dseek1);
        tv_dseek1=findViewById(R.id.tv_dseek1);
        arcMaskCircilarView = findViewById(R.id.mask_view2);
//set value(max and min) of seekbar
// ---------------mArcSeekBar的最大值最小值设置
        mArcSeekBar.setMaxValue(100);
        mArcSeekBar.setMinValue(0);
        //setEngry(mArcSeekBar.getProgress());

        listening();








//        findViewById(R.id.btn_0).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mArcSeekBar.setProgress(0);
//            }
//        });
//
//        findViewById(R.id.btn_90).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                mArcSeekBar.setProgress(90);
//            }
//        });
    }
    private  void initcolor(){

        Color.colorToHSV(mcolor, hsv);
        mHue = hsv[0];//色调范围0-360
        mSat =  hsv[1];//饱和度范围0-1
        mVal =  hsv[2];//亮度范围0-1
    }
public  void listening() {

        //灯泡总开关
    light_icon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if (color_icon == gray) {
                light_icon.setColorFilter(color_icon);
                color_icon = -1;
                //send data of lighting on


            } else if (color_icon == -1) {

                light_icon.setColorFilter(color_icon);
                color_icon = gray;
            }
        }
    });

    dseek1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean b) {
            tv_dseek1.setText(progress + "%");

            Color.colorToHSV(mcolor, hsv);
            mHue = hsv[0];
            mSat = hsv[1];
            mVal= (float) progress / seekBar.getMax();
//            if (mVal < 0.35) {
//                mVal = 0.35f;
//            }\
           mcolor = Color.HSVToColor(new float[]{mHue, mSat, mVal});


            arcMaskCircilarView.setColor(mcolor);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }

    });


    mArcSeekBar.setOnProgressChangeListener(new ArcSeekBar.OnProgressChangeListener() {
        @Override
        public void onProgressChanged(ArcSeekBar seekBar, int progress, boolean isUser) {
            setEngry(seekBar.getProgress());
//            int color1=seekBar.getColor();
//            Color.colorToHSV(color1, hsv);
//            mHue = color1;
//            mSat = hsv[1];
//            mVal =  hsv[2];
//
//        //    mcolor=Color.HSVToColor(new float[]{mHue, mSat, mVal});
//            arcMaskCircilarView.setColor(Color.HSVToColor(new float[]{mHue, mSat, mVal}));
            mcolor = seekBar.getColor();
            arcMaskCircilarView.setColor(mcolor);

        }

        @Override
        public void onStartTrackingTouch(ArcSeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(ArcSeekBar seekBar) {
            setEngry(seekBar.getProgress());
        }

        @Override
        public void onColorListening(ArcSeekBar seekBar,int color){
//            mcolor=seekBar.getColor();
//            //mcolor = color;
//            arcMaskCircilarView.setColor(mcolor);
        }

    });
}
    private void setEngry(int progress) {
        mProgressText.setText( +mArcSeekBar.getProgress() + " %");
    }
}
